<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 查询区域 -->
<!--    <div class="table-page-search-wrapper">-->
<!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--        <a-row :gutter="24">-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="任务描述">-->
<!--              <a-input placeholder="请输入任务描述" v-model="queryParam.taskDes"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="任务状态">-->
<!--              <j-dict-select-tag placeholder="请选择任务状态" v-model="queryParam.taskState" dictCode="pm_project_task_state"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <template v-if="toggleSearchStatus">-->
<!--          </template>-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
<!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
<!--              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
<!--            </span>-->
<!--          </a-col>-->
<!--        </a-row>-->
<!--      </a-form>-->
<!--    </div>-->
    <!-- 查询区域-END -->


    <!-- 操作按钮区域 -->
<!--    <div class="table-operator">-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel">-->
<!--            <a-icon type="delete"/>-->
<!--            删除-->
<!--          </a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作-->
<!--          <a-icon type="down"/>-->
<!--        </a-button>-->
<!--      </a-dropdown>-->
<!--    </div>-->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a-->
<!--        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot='taskDes' slot-scope='text'>
          <j-ellipsis :value='text' :length='10'/>
        </template>
        <template slot='incompleteCause' slot-scope='text'>
          <j-ellipsis :value='text' :length='10'/>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>

    <hfPmProjectTasks-modal ref="modalForm" @ok="modalFormOk" :mainId="mainId"></hfPmProjectTasks-modal>
  </a-card>
</template>

<script>

import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import HfPmProjectTasksModal from './modules/HfPmProjectTasksModal'
import {getAction} from '@api/manage'

export default {
  name: "HfPmProjectTasksListTab",
  mixins: [JeecgListMixin],
  components: {HfPmProjectTasksModal},
  data() {
    return {
      description: '双周计划表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '专题名称',
          align: "center",
          dataIndex: 'subjectName'
        },
        {
          title: '目标名称',
          align: "center",
          dataIndex: 'targetName'
        },
        {
          title: '任务描述',
          align: "center",
          dataIndex: 'taskDes',
          scopedSlots: {customRender: 'taskDes'},
          width: 300
        },
        {
          title: '任务状态',
          align: "center",
          dataIndex: 'taskState_dictText',
        },
        {
          title: '责任人',
          align: "center",
          dataIndex: 'dutyPersionId_dictText'
        },
        {
          title: '检查人',
          align: "center",
          dataIndex: 'examiner_dictText'
        },
        {
          title: '未完成原因',
          align: "center",
          dataIndex: 'incompleteCause',
          scopedSlots: {customRender: 'incompleteCause'}
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        list: "/pm/hfPmDoubleWeekPlan/listHfPmProjectTasks",
        delete: "/pm/hfPmDoubleWeekPlan/deleteHfPmProjectTasks",
        deleteBatch: "/pm/hfPmDoubleWeekPlan/deleteBatchHfPmProjectTasks",
        exportXlsUrl: "/pm/hfPmDoubleWeekPlan/exportHfPmProjectTasks",
        importUrl: "/pm/hfPmDoubleWeekPlan/importHfPmProjectTasks",
        changeTaskStatus: 'pm/hfPmDoubleWeekPlan/changeTaskStatus',
        queryTasks: 'pm/hfPmProjectTargets/queryTasks',
      },
      disableMixinCreated: true,
    }
  },
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    },
    planType: {
      type: String,
      default: '',
      required: false
    },
    // selectedLeftTreeData: {
    //   type: Object,
    //   default: () => {
    //   },
    // },
  },
  created() {
  },
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`;
    }
  },
  // watch: {
  //   selectedLeftTreeData: {
  //     immediate: true,
  //     deep: true,
  //     handler(val) {
  //       if (val.selectedTreeType === 'project') {
  //         this.getListBySelectedKey(val.selectedKeys)
  //       } else if (val.selectedTreeType === 'subject') {
  //         this.getListBySelectedKey(val.selectedSubKeys)
  //       }
  //     },
  //   },
  // },
  methods: {
    // getListBySelectedKey(id) {
    //   if (this.selectedLeftTreeData.selectedTreeType === 'project') {
    //     this.propsParams = {projectId: id}
    //     this.loadData()
    //   } else if (this.selectedLeftTreeData.selectedTreeType === 'subject') {
    //     this.propsParams = {subjectId: id}
    //     this.loadData()
    //   }
    // },
    searchQuery() {
      this.loadData(1);
    },
    getListBySelectedKey2(id){
      this.propsParams = {targetId: id}
      this.loadData()
    },
    loadData() {
      let params = Object.assign({}, this.getQueryParams(), this.propsParams)
      this.loading = true;
      getAction(this.url.queryTasks, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total;
        }
      }).finally(() => {
        this.loading = false;
      })
    },
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    },
    handleEdit: function (record) {
      //计划未发布可编辑全部、计划已发布只能修改任务状态
      if (this.planType == "2") {
        this.$message.error('总结计划的任务不可编辑!');
        return;
      }
      if (record.taskState == "4") {
        this.$message.error('该任务已完成，不可再次编辑!');
        return;
      }
      //1:计划状态为未发布，能修改任务的所有信息
      if (this.planType == "1") {
        record.editType = 'editAll';
      }
      //3:计划状态为已发布，只能修改任务的状态，其他信息不可编辑
      if (this.planType == "3") {
        record.editType = 'edit';
      }
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.disableSubmit = false;
    },
    handleDetail: function (record) {
      record.editType = 'view';
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "详情";
      this.$refs.modalForm.disableSubmit = true;
    },
    handleAdd: function () {
      this.$refs.modalForm.add();
      this.$refs.modalForm.title = "新增";
      this.$refs.modalForm.disableSubmit = false;
      // this.$refs.modalForm.defaultModel = this.selectedLeftTreeData
    },
    //任务检查
    taskExaminer: function (record) {
      if ('3' != this.planType) {
        this.$message.error('请选择已发布状态的计划的任务进行检查!');
        return;
      }
      if ('1' != record.taskState) {
        this.$message.error('请操作未开始的任务!');
        return;
      }

      if (null != record.examiner || '' != record.examiner || undefined != record.examiner) {
        this.$message.error('该任务已经检查完成，请操作其他任务!');
        return;
      }
      record.changeTaskStatus = '检查';
      getAction(this.url.changeTaskStatus, record).then((res) => {
        if (res.success) {
          this.loadData()
          this.$message.success("任务已经检查完成。")
        } else {
          this.$message.warning("任务检查操作失败！")
        }
      })
    },
    taskEnd: function (record) {
      if ('2' != record.taskState) {
        this.$message.error('请操作进行中的任务!');
        return;
      }
      record.changeTaskStatus = '4';
      getAction(this.url.changeTaskStatus, record).then((res) => {
        if (res.success) {
          this.loadData()
          this.$message.success("任务已经完成。")
        } else {
          this.$message.warning("任务完成操作失败！")
        }
      })
    },
    taskEx: function (record) {
      if ('2' != record.taskState) {
        this.$message.error('请操作进行中的任务!');
        return;
      }
      record.changeTaskStatus = '3';
      getAction(this.url.changeTaskStatus, record).then((res) => {
        if (res.success) {
          this.loadData()
          this.$message.success("任务状态已经修改为异常。")
        } else {
          this.$message.warning("任务异常处理失败！")
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>
